// pages/userStatistics/AddPersonnel/addQ.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    icon1:"https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/account/20211130/915258332296511488.png",
    icon2:"https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/account/20211130/915258317419315200.png",
    QXList:[
      {
        name:"用户权限",
        tips:"(包含普通用户、普通会员、VIP会员、股东)",
        selected:false,
        power:"USER"
      },
      {
        name:"订单权限",
        tips:"(包含线上、线下开单、预约管理)",
        selected:false,
        power:"ORDER"
      },
      {
        name:"核销权限",
        tips:"(包含优惠券核销、商品核销、套餐卡核销)",
        selected:false,
        power:"WRITE_OFF"
      },
      {
        name:"轮播图权限",
        tips:"",
        selected:false,
        power:"ROTATION"
      },
      {
        name:"商品权限",
        tips:"(包含普通商圈、云商品)",
        selected:false,
        power:"GOODS"
      },
      {
        name:"员工权限",
        tips:"(注意:拥有该权限店员可以操作权限管理)",
        selected:false,
        power:"STAFF"
      },
      {
        name:"拼团权限",
        tips:"",
        selected:false,
        power:"PIN"
      },
      {
        name:"优惠券权限",
        tips:"",
        selected:false,
        power:"COUPON"
      },
      {
        name:"会员卡权限",
        tips:"(包含套餐卡、充值卡、引流卡、线下开卡)",
        selected:false,
        power:"VIP"
      },
      {
        name:"红包权限",
        tips:"",
        selected:false,
        power:"RED"
      },
      {
        name:"商圈权限",
        tips:"",
        selected:false,
        power:"GROUP"
      },
      {
        name:"评论权限",
        tips:"",
        selected:false,
        power:"COMMENT"
      },
      {
        name:"查看营收",
        tips:"",
        selected:false,
        power:"REVENUE"
      },
      {
        name:"记账",
        tips:"",
        selected:false,
        power:"BOOK"
      },
      {
        name:"邀请函",
        tips:"",
        selected:false,
        power:"INVITATION"
      }
    ]
  },

  //选择权限
  selectQX(e){
    let index=e.currentTarget.dataset.index
    let list=this.data.QXList
    if(list[index].selected==false){
      list[index].selected=true
    }else{
      list[index].selected=false
    }
    this.setData({
      QXList:list
    })
  },

  getBack(){
    wx.navigateBack()
  },

  //确定返回权限
  getQXListBack(){
    let list=this.data.QXList
    let QXSelectList=[]
    let powerList=[]
    list.forEach(item=>{
      if(item.selected==true){
        QXSelectList.push(item)
        powerList.push(item.power)
      }
    })
    let pages=getCurrentPages()
    let lastPage=pages[pages.length-2]
    
    lastPage.setData({
      QXSelectList:QXSelectList,
      'value.power':powerList.join(",")
    })
    wx.navigateBack()
  },


  //判断权限
  judgePower(){
    let havePower=this.data.QXList
    let power=this.data.power.split(",")
    havePower.forEach(item=>{
      power.forEach(secondItem=>{
        if(item.power==secondItem){
          item.selected=true
        }
      })
    })
    this.setData({
      QXList:havePower
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      power:options.power
    })
    this.judgePower()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})